Tips&Tricks | I trucchi del mestiere |
![]() |
Acquisire immagini tramite scanner |
Private Sub Form_Load() Command1.Caption = "Scannerizza!" Label1.Caption = "Staus: none" End Sub Private Sub Command1_Click() ' scanner pronto? ImgScan1.ScannerAvailable ' apre la porta dello scanner ImgScan1.OpenScanner ' inizia la scansione ImgScan1.StartScan End Sub Private Sub ImgScan1_PageDone(ByVal PageNumber As Long) Label1.Caption = "status: page " & PageNumber & " done." 'salva l'immagine al percorso specificato ImgEdit1.SaveAs "c:\provascan.jpg", 6 End Sub Private Sub ImgScan1_ScanDone() Label1.Caption = "status: scan done." End Sub Private Sub ImgScan1_ScanStarted() Label1.Caption = "status: scan started." End Sub |
![]() |
Una console per le vostre applicazioni |
Private Declare Function AllocConsole Lib "kernel32" () As Long Private Declare Function FreeConsole Lib "kernel32" () As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal handleObj As Long) As Long Private Declare Function GetStdHandle Lib "kernel32" (ByVal handle As Long) As Long Private Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" _ (ByVal hConsoleOutput As Long, lpBuffer As Any, ByVal _ nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, _ lpReserved As Any) As Long Private Const STD_OUTPUT_HANDLE = -11& Dim hConsole As Long Private Sub btnTest_Click() Dim retCode As Long, stdOut As String, byteScritti As Long stdOut = vbCrLf & "Grazie per aver provato !!!" & vbCrLf retCode = WriteConsole(hConsole, ByVal stdOut, Len(stdOut), byteScritti, ByVal 0&) Shell App.Path & "\TEST.BAT" End Sub Private Sub Form_Load() hConsole = IstanziaConsole End Sub Private Sub Form_Unload(Cancel As Integer) RilasciaConsole hConsole End Sub Function IstanziaConsole() As Long IstanziaConsole = 0 If AllocConsole() Then IstanziaConsole = GetStdHandle(STD_OUTPUT_HANDLE) If IstanziaConsole = 0 Then MsgBox "Impossibile reindirizzare l'output sulla Console", vbOKOnly + vbCritical End If Else MsgBox "Impossibile aprire la Console", vbOKOnly + vbCritical End If End Function Function RilasciaConsole(handleConsole As Long) CloseHandle handleConsole FreeConsole End Function |
![]() |
Un semplice autocomplete dei form di IE |
Option Explicit Private winTitolo As String 'Verifico se l'oggetto passatomi e' un campo di tipo password Private Function IsPasswordBox(Elemento As Object) As Boolean On Error GoTo err_password If LCase(Elemento.getAttribute("Type")) = "password" Then IsPasswordBox = True Else IsPasswordBox = False End If Exit Function err_password: IsPasswordBox = False End Function 'Verifico se il campo e' una text box Private Function IsTextBox(Elemento As Object) As Boolean On Error GoTo err_text If LCase(Elemento.getAttribute("Type")) = "text" Then IsTextBox = True Else IsTextBox = False End If Exit Function err_text: IsTextBox = False End Function Private Function CercaCampi(Documento As Object) As Boolean Dim Elemento As Object Dim numOggetti As Long Dim indiceOggetti As Long Dim Trovato As Boolean Dim ok As Integer 'Prendo il numero degli oggetti nel documento numOggetti = Documento.All.length 'Scorro gli elementi fino a trovarne uno di tipo password o text For indiceOggetti = 0 To numOggetti - 1 DoEvents Set Elemento = Documento.All.Item(indiceOggetti) 'Verifico se e' una password-box e la riempio con la parola pluto If IsPasswordBox(Elemento) Then 'Il false serve per rendere case-insensitive la ricerca dell'attributo value ok = Elemento.setAttribute("Value", "pluto", False) Trovato = True End If 'Verifico se e' una text-box e la riempio con la parola paperino If IsTextBox(Elemento) Then 'Il false serve per rendere case-insensitive la ricerca dell'attributo value ok = Elemento.setAttribute("Value", "paperino", False) Trovato = True End If Next numOggetti = Documento.frames.length 'Eseguo la verifica anche su eventuali frame nella pagina For indiceOggetti = 0 To numOggetti - 1 'Esegui la ricerca anche in questi frame If CercaCampi(Documento.frames.Item(indiceOggetti).document) Then Trovato = True Next CercaCampi = Trovato End Function Private Sub Scansiona() Dim objShellWins As New SHDocVw.ShellWindows Dim objExplorer As SHDocVw.InternetExplorer Dim Documentoument As HTMLDocument Dim Trovato As Boolean Dim Eseguito As Boolean Screen.MousePointer = vbHourglass 'Scorri tutte le fineste aperte For Each objExplorer In objShellWins If TypeOf objExplorer.document Is HTMLDocument Then Set Documentoument = objExplorer.document 'Salva il titolo cosi' da poterle riconoscere winTitolo = Documentoument.Title 'Comincia la ricerca nel documento Eseguito = CercaCampi(Documentoument) If Eseguito Then Trovato = True End If Next Screen.MousePointer = vbDefault End Sub Private Sub cmdPasswords_Click() Scansiona End Sub |
![]() |
Salvare un grafico MSChart come immagine |
Public Sub SalvaMSChart(Graph As MSChart, pic As PictureBox, ByVal FileName As String) 'Copia il grafico nella clipboard Graph.EditCopy ' Imposta la picture della PicBox pic.Picture = Clipboard.GetData(vbCFMetaFile) ' Salva l'immagine SavePicture pic.Picture, FileName End Sub |